﻿using Cxuu.Common;
using Cxuu.Models;
using Microsoft.Extensions.DependencyInjection;
using PetaPoco;
using System.Threading.Tasks;

namespace Cxuu.Repository
{
    [UseDI(ServiceLifetime.Scoped)]
    public class ExtMemberRepository : BaseRepository<ExtMember, PetaPocoContext>
    {

        public ExtMemberRepository(PetaPocoContext petaPocoContext) : base(petaPocoContext) { }


        /// <summary>
        /// 联表查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<Page<ExtMember>> GetPageListAsync(string keyword, int page, int limit, int? status)
        {
            Sql sql = Sql.Builder;
            sql.Select("*")
                .From("cxuu_ext_member");

            if (!string.IsNullOrEmpty(keyword))
                sql.Where("Name like @0", "%" + keyword + "%");

            if (status != null)
                sql.Where("Status = @0", status);

            sql.OrderBy("Sort asc,Id desc");
            return await CreateDAO().PageAsync<ExtMember>(page, limit, sql);
        }

    }
}
